﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MeTalker.Model;
using MeTalker.BLL;

public partial class Default_AddMembers : WebForm
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            List<SoftwaresMod> Softwaress = SoftwaresBLL.GetSoftwares();
            txtSoftName.DataTextField = "SoftName";
            txtSoftName.DataValueField = "SoftID";
            txtSoftName.DataSource = Softwaress;
            txtSoftName.DataBind();
        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        MembersMod membes = new MembersMod();
        membes.UserName = txtUserName.Text;
        membes.Email = txtEmail.Text;
        membes.QQ = txtQQ.Text;
        membes.MobilePhone = txtMobilePhone.Text;
        membes.Password = txtPass.Text;
        if (string.IsNullOrEmpty(membes.UserName))
        {
            Alert("用户名不能为空!");
            return;
        }
        if (string.IsNullOrEmpty(membes.Password))
        {
            Alert("密码不能为空!");
            return;
        }
        membes.Password = GetMD5(membes.Password);
        SoftwaresMod software = SoftwaresBLL.GetSoftware(txtSoftName.SelectedValue);
        int errcode = 0;
        if (MembersBLL.CheckUserName(membes.UserName, software.SoftID, out errcode))
        {
            Alert("该用户已经存在");
            return;
        }
        membes.SoftName = software.SoftName;
        membes.SoftID = software.SoftID;
        membes.RegistDate = DateTime.Now;
        membes.ExpireDate = DateTime.Now.AddDays(software.TrialDays);
        membes.LoginFlag = false;
        membes.IsValid = true;
        membes.Memo = "";
        membes.HDID = "system";
        membes.SessionId = Session.SessionID;
        membes.AddDate = membes.RegistDate;
        membes.UserType = "0";
        membes.SoftID = software.SoftID;
        membes.SoftName = software.SoftName;
        if (MembersBLL.Insert(membes) > 0)
        {
            Alert("用户添加成功!", "closePanel", "RefreshData");
            //Alert("用户添加成功");
        }
        else
        {
            Alert("用户添加失败!");
        }
    }
}